package com.it.ssh.action;

import java.util.List;

import com.it.ssh.entity.BookUser;
import com.it.ssh.service.BookUserService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class BookUserAction extends ActionSupport implements ModelDriven<BookUser> {
	BookUser user = new BookUser();
	
	
	private BookUserService bookUserService;

	
	public void setBookUserService(BookUserService bookUserService) {
		this.bookUserService = bookUserService;
	}
	private List<BookUser> list;
	
	public List<BookUser> getList() {
		return list;
	}
	public void setList(List<BookUser> list) {
		this.list = list;
	}
	@Override
	public BookUser getModel() {
		// TODO Auto-generated method stub
		return user;
	}
	public String login() throws Exception {
		boolean flag=bookUserService.login(user);
		System.out.println(flag);
		String path=INPUT;
		if(flag){
			path=SUCCESS;
		}
		return path;
	}
	public String delete() throws Exception {
		boolean flag = bookUserService.delete(user.getId());
		System.out.println("hello:"+user.getId());
		String path = INPUT;
		if(flag) {
			path = SUCCESS;
		}
		return path;
	}
	public String queryAll() throws Exception {
		list=bookUserService.queryAll();		
		return SUCCESS;
	}
	public String queryById(int id) {
		user = bookUserService.queryById(id);
		return SUCCESS;
	}
	public String add() {
		boolean flag = bookUserService.add(user);
		String path = INPUT;
		if(flag) {
			path = SUCCESS;
		}
		return path;
	}
	public String update() {
		boolean flag = bookUserService.update(user);
		String path = INPUT;
		if(flag) {
			path = SUCCESS;
		}
		return path;
	}
	
}
